﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections;
using System.Data.SqlClient;

namespace Lyon.Data.ORM.DataBases
{
    /// <summary>
    /// SQLSERVER数据库。
    /// </summary>
    public class DataBaseForSqlserver : AbstractDataBase, IDataBase
    {
        string _ConnectionString;

        /// <summary>
        /// 创建一个打开的数据库连接。
        /// </summary>
        protected override IDbConnection CreateConnection()
        {
            SqlConnection conn = new SqlConnection(_ConnectionString);
            return conn;
        }
        /// <summary>
        /// 参数名前缀。
        /// </summary>
        protected override string ParameterNamePrefix
        {
            get { return "@"; }
        }
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="serverName">服务器地址或名称</param>
        /// <param name="databaseName">数据库名称</param>
        public DataBaseForSqlserver(string serverName, string databaseName)
        {
            Guard.ArgumentNotNullOrEmptyString(serverName, "serverName");
            Guard.ArgumentNotNullOrEmptyString(databaseName, "databaseName");
            _ConnectionString = String.Format("Data Source={0};Initial Catalog={1};Integrated Security=True", serverName, databaseName);
        }
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="serverName">服务器地址或名称</param>
        /// <param name="databaseName">数据库名称</param>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        public DataBaseForSqlserver(string serverName, string databaseName, string userName, string password)
        {
            Guard.ArgumentNotNullOrEmptyString(serverName, "serverName");
            Guard.ArgumentNotNullOrEmptyString(databaseName, "databaseName");
            Guard.ArgumentNotNullOrEmptyString(userName, "userName");
            Guard.ArgumentNotNullOrEmptyString(password, "password");
            _ConnectionString = String.Format("Data Source={0};Initial Catalog={1};User ID={2};Password={3}", serverName, databaseName, userName, password);
        }
    }
}